#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include <unistd.h>
#include <signal.h>
#include <setjmp.h>

jmp_buf env_alarm;

void sig_alarm(int signo) {
	longjmp(env_alarm, 1);
}

int main() {
	int n;
	char line[1024];

	if (signal(SIGALRM, sig_alarm) == SIG_ERR) {
		printf("signal error\n");
		return -1;
	}

	if (setjmp(env_alarm) != 0) {
		printf("timeout setjmp error: %s\n", strerror(errno));
		return -1;
	}

	alarm(5);
	if ((n=read(STDIN_FILENO, line, 1024)) < 0) {
		printf("read error\n");
		return -1;
	}

	alarm(0);
	write(STDOUT_FILENO, line, n);
	return 0;
}